package com.ruoyi.quartz.task;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.quartz.service.IPlanBusBService;
import com.ruoyi.quartz.service.IPlanBusCService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component("planTaskC")
public class PlanTaskC {

    @Autowired
    private IPlanBusCService planBusCService;

    @Autowired
    private ISysConfigService configService;

    public void planAm(Integer day) {
        //Date date = null;//测试，上线需屏蔽掉此部分代码
        Date date = DateUtils.getAfterTime(day);
        planBusCService.plan("am", date);
        changeDriveUserTask("am", date);
    }

    public void planPm(Integer day) {
        Date date = DateUtils.getAfterTime(day);
        planBusCService.plan("pm", date);
        changeDriveUserTask("pm", date);
    }

    private void changeDriveUserTask(String driveTimes, Date date){
        String value = configService.selectConfigByKey("change_task");
        if("0".equals(value)){
            planBusCService.changePlanUser(driveTimes, date);
        }
    }
}
